import sys
import thread
import time

from algorithm import *
from md5_hash import *
from sha1_hash import *
from bruteforce_alphabet import *

if __name__ == '__main__':
	isThreaded = False
	if len(sys.argv) == 3:
		if sys.argv[1] != "seq" and sys.argv[1] != "par":
			print "Please provide a valid execution mode (seq, par)!"
			exit
		else:
			isThreaded = sys.argv[1] == "par"
			# add implemented algorithms
			alphabet = BruteforceAlphabet().getAlphabetList()
			algorithmList = []
			algorithmList.append(Algorithm(sys.argv[1], alphabet, isThreaded, Md5Hash()))
			algorithmList.append(Algorithm(sys.argv[1], alphabet, isThreaded, Sha1Hash()))
			activeThreadList = []
			for algorithm in algorithmList:
				if not isThreaded:
					algorithm.bruteForce()
				else:
					thread.start_new_thread(algorithm.bruteForce, ())
			if isThreaded:
				time.sleep(1)
	else:
		print "Hashpy needs two arguments"
		print "The first argument is 'seq' or 'par' for executing the algorithm sequentiel or threaded"
		print "The second argument is the hashcode password we want to bruteforce"
